package com.ah.suams.service.impl;

import com.ah.suams.bean.Member;
import com.ah.suams.dao.DeptDao;
import com.ah.suams.dao.JobDao;
import com.ah.suams.dao.MemberDao;
import com.ah.suams.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    private DeptDao deptDao;

    @Autowired
    private JobDao jobDao;

    @Autowired
    private MemberDao memberDao;

    @Override
    public Member member(String id) {
        return memberDao.member(id);
    }

    @Override
    public List<Member> memberList(String id, String name, String deptName) {
        String deptId = null;
        if(deptName != null){
            deptId = deptDao.selectIdByName(deptName);
        }

        return memberDao.memberList(id,name,deptId);
    }

    @Override
    public int updateMember(String id, String password, String name,
                            String sex, String birthday, String jointime,
                            String phone, String email, String deptName, String jobName) {
        String deptId = deptDao.selectIdByName(deptName);
        String jobId = jobDao.selectIdByName(jobName);
        return memberDao.updateMember(id,password,name,sex,birthday,jointime,phone,email,deptId,jobId);
    }

    @Override
    public int addMember(String id, String password, String name,
                         String sex, String birthday, String jointime,
                         String phone, String email, String deptName, String jobName) {
        String deptId = deptDao.selectIdByName(deptName);
        String jobId = jobDao.selectIdByName(jobName);
        return memberDao.insertMember(id,password,name,sex,birthday,jointime,phone,email,deptId,jobId);
    }

    @Override
    public int deleteMember(String id) {
        return memberDao.deleteMember(id);
    }
}
